How can I call a custom Error Page when an Item requested in the URL does not exist?
There are at least two ways.
There is a special web.config parameter
<!-- ITEM NOT FOUND HANDLER
Url of page handling 'Item not found' errors
-->
<setting name="ItemNotFoundUrl" value="/Errors/MyErrorPage.html" />
You can replace a Sitecore error page with a custom one.
You can write your own processor for the httpRequestBegin pipeline:
<pipelines>
<httpRequestBegin>
…
<processor type="Sitecore.Pipelines.HttpRequest.LayoutResolver, Sitecore.Kernel" />
<processor type="CustomHttpRequestHandler.MyHttpHandler, CustomHttpRequestHandler" />
<processor type="Sitecore.Pipelines.HttpRequest.ExecuteRequest, Sitecore.Kernel" />
</httpRequestBegin>
and use the following code for the CustomHttpRequestHandler:
namespace CustomHttpRequestHandler
{
public class MyHttpHandler
{
public void Process(HttpRequestArgs args)
{
if (args.LocalPath.IndexOf("/sitecore/") == -1 && args.FilePath.IndexOf("/sitecore/") == -1 && Context.Item == null )
{
WebUtil.Redirect("http://localhost/MyCustomErrorPage.html");
args.Abort();
return;
}
}
}
}